import Vue from 'vue'
import App from '@/App'
// import router2 from '@/router/index2.js'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import '@/element-ui'                         // api: https://github.com/ElemeFE/element
import 'element-ui/lib/theme-chalk/index.css'
import '@/icons'                              // api: http://www.iconfont.cn/
import '@/element-ui-theme'
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import httpRequest1 from '@/utils/httpRequest1'
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import currentUser from '@/global/currentUser'

Vue.use(VueCookie)
Vue.config.productionTip = false

// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
if (process.env.NODE_ENV !== 'production') {
  require('@/mock')
}

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.$http1 = httpRequest1
Vue.prototype.isAuth = isAuth     // 权限方法
Vue.prototype.currentUser = currentUser

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App },

  data() {
    return {
      // this.$root.user.nickName
      // user: {
      //   uid: 0,
      //   nickName: 'zhang',
      //   stuid: '123456789',
      //   portrait: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
      // }
    }
  },
  methods: {
    // changeUser(one){
    //   this.user.uid = one.uid;
    //   this.user.nickName = one.nickName;
    //   this.user.stuid = one.stuid;
    //   if (typeof one.portrait == "undefined" || one.portrait == null || one.portrait == "") {
        
    //   } else {
    //     this.user.portrait = one.portrait;
    //   }
    //   console.log("changeUser",this.user)
    // },
    changeCurrentUser(one){
      let user = this.currentUser.user;
      user.uid = one.uid;
      user.nickName = one.nickName;
      user.stuid = one.stuid;
      if (typeof one.portrait == "undefined" || one.portrait == null || one.portrait == "") {
        
      } else {
        user.portrait = one.portrait;
      }
      console.log("changeCurrentUser",user)
    },
    updateUserPortrait(portrait){
      let user = this.currentUser.user;
      user.portrait = portrait;
      console.log("新头像",user.portrait)
    }
  },
})
